/**
 * FileName: SickbedController
 * Author:   P
 * Date:     2021/3/3 15:47
 * Description:
 */
package com.hospital.nurse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.hospital.nurse.pojo.Sickbed;
import com.hospital.nurse.service.SickbedService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/sickbed")
public class SickbedController {


    @Autowired
    private SickbedService sickbedService;


   /* @RequestMapping("/sickbeds/{page}/{size}")
    public IPage<Sickbed> sickbedIPage(@PathVariable int size,@PathVariable int page){
        IPage<Sickbed> sickbeds = new Page<>(page, size);

        return service.page(sickbeds);
    }*/

    @RequestMapping("/sickbeds/{page}/{size}")
    public PageInfo<Sickbed> sickbedIPage(@PathVariable int size, @PathVariable int page) {
        IPage<Sickbed> sickbeds = new Page<>(page, size);

        return new PageInfo<>(sickbedService.getSickAndPatients());
    }
    
    
    @RequestMapping("findsickbed/{sid}")
    public Map<String,Object> findSickbed(@PathVariable int sid){
        Map<String, Object> map = new HashMap<>();
        Sickbed scikbedPatient = sickbedService.getScikbedPatient(sid);
        List<Sickbed> list = sickbedService.list(new QueryWrapper<Sickbed>().select("s_id").eq("s_isNull", 1));
        map.put("msg",scikbedPatient);
        map.put("ids",list);
        return map;
    }


    //修改病床
    @RequestMapping("/editsickbed/{sid}/{pid}")
    public String editsickbed(@PathVariable int sid,@PathVariable int pid){
        //修改原来的 病床号
        Sickbed one = sickbedService.getOne(new QueryWrapper<Sickbed>().eq("p_id", pid));
        //把病床置为0
        sickbedService.editSickebed(one.getSId(),0);
        sickbedService.editSickebed(sid,pid);
        return "修改成功";
    }


    //修改病床
    @RequestMapping("/bed_isNull")
    public Map<String,Object> bedNull(){
        List<Sickbed> list = sickbedService.getNullBed();
        Map<String, Object> map = new HashMap<>();
        map.put("msg",list);
        return map;
    }

    //获取所属科室的所有空床
    @RequestMapping("/getDepNullBed/{did}")
    public Map<String,Object> getDepNullBed(@PathVariable int did){
        Map<String, Object> map = new HashMap<>();
        map.put("list",sickbedService.getDepNullBed(did));
        return map;
    }

}
